<?php
/*
class site_dao_entry extends ss_dao_entry{
	
	public function getMasterData(){
		$result=array();
		foreach(array('primary','slug','headline','teaser','catdata') as $val){
			$result[$val]=$this->{$val}();
		}
		return $result;
	}
	public function getDetailData(){
		$result=array('primary'=>$this->primary(),'catdata'=>$this->catdata());
		foreach(array_keys($this->attributes) as $val){
			$result[$val]=$this->{$val}();
		}
		return $result;
	}
	public function catdata(){
		return array(
			'id'=>$this->catidlist(),
			'slug'=>$this->catsluglist(),
			'name'=>$this->catnamelist());
	}
	
}
*/

class site_dao_entry_mapper extends ss_dao_entry_mapper{
	protected $table='entry';
	protected $primary='identry';
	
	public function getEntryByID($id){
		
	}
	/*
	public function getEntries($lnum=10,$lstart=0){
		$query=$this->injector->create('ss_dao_query');
		$sql=$query
		->from(array(
			'getentry'))
		->where(array(
			array(
				'lft'=>'date_rej',
				'cmp'=>'IS',
				'rgt'=>array('com'=>'NULL')
			),
			array(
				'ar'=>'OR',
				'lft'=>'date_rej',
				'cmp'=>'>',
				'rgt'=>array('com'=>'NOW()')
				)))
		->limit($lnum,$lstart)
		->select();
		$stmt=$this->da->runStmt($sql,$query->values());
		//$stmt=$this->da->prepare($sql);
		//$this->da->execute($stmt,$query->values());
		return $this->getArray($stmt);
	}
	*/
	
	public function api_master($query=null){
		$q=$this->injector->create('ss_dao_query');
		$sql=$q
		->from(array(
			'site_entry'))
		->where(array($query))
		->select();
		$stmt=$this->da->runStmt($sql,$q->values());
		return $this->getArray($stmt);
	}
	
	public function master($query=null){
		$q=$this->injector->create('ss_dao_query');
		$sql=$q
		->from(array(
			'ss_entry'))
		->where(array($query))
		->select();
		$stmt=$this->da->runStmt($sql,$q->values());
		return $this->getArray($stmt);
	}
	
	public function api_detail($id){
		$q=$this->injector->create('ss_dao_query');
		$sql=$q
		->from(array(
			'site_entry'))
		->where(array(
			array($this->primary=>$id))
			)
		->select();
		$stmt=$this->da->runStmt($sql,$q->values());
		return $stmt->fetchObject($this->getObjectString('dao_entry'),array($this->primary));
	}
	
	private function getArray($stmt){
		$result=array();
		while($obj=$stmt->fetchObject($this->getObjectString('dao_entry'),array($this->primary))){
			$result[]=$obj->clean();
		}
		$this->da->closeCursor($stmt);
		return $result;
	}
	
	public function getLatestActiveEntries($num=null,$start=null){
		$query=$this->injector->create('ss_dao_query');
		$sql=$query->
		from(array(
			'ss_entry'))->
		where(array(
			array(
				'lft'=>'date_rej',
				'cmp'=>'IS',
				'rgt'=>array('com'=>'NULL')
			),
			array(
				'ar'=>'OR',
				'lft'=>'date_rej',
				'cmp'=>'>',
				'rgt'=>array('com'=>'NOW()')
				)))->
		limit($num,$start)->
		select();
		$stmt=$this->da->runStmt($sql,$query->values());
		//$stmt=$this->da->prepare($sql);
		//$this->da->execute($stmt,$query->values());
		return $this->getArray($stmt);
	}
	
	public function insert(ss_dao_object_interface $obj){
		
	}
	/*
	public function update(ss_dao_object_interface $obj){
		$result=array();
		$changed=array();
		foreach($obj->changed() as $val) $changed[$val]=$obj->{$val};
		if(count($changed)==0) return false;
		foreach($this->location['entry'] as $val){
			if(array_key_exists($val,$changed)) $result['entry'][$val]=$changed[$val];
		}
		foreach($this->location['entry_has_category'] as $val){
			if(array_key_exists($val,$changed)) $result['entry_has_category'][$val]=$changed[$val];
		}
		foreach($this->location['entry_has_staff'] as $val){
			if(array_key_exists($val,$changed)) $result['entry_has_staff'][$val]=$changed[$val];
		}
		ss_error::log($result,'Changed data');
		if(isset($result['entry'])){
			if(!$obj->{$this->primary}) return $this->insert($obj);
			$q=$this->injector->create('ss_dao_query');
			$sql=$q->from(array(
				$this->table))
			->set(array($result['entry']))
			->where(array(
				array($this->primary=>$obj->{$this->primary}))
				)
			->update();
			ss_error::log($sql);
			ss_error::log($q->values());
			$stmt=$this->da->runStmt($sql,$q->values());
		}
		return $obj;
		//if(isset($result['entry_has_category'])) $this->setEntryCat($obj);
		//return false;
	}
	*/
	
	public function delete(ss_dao_object_interface $obj){
		
	}
}
?>